<extend name="Public/base"/>

<block name="body">
    <include file="Public:sui" />
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <form action="{:U('saveStudent')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">学员姓名<span class="check-tips"></span></label>
            <div class="controls">
                <span class="sui-text-info" id="student_name" style=" font-size:20px;margin-right: 100px;"></span>
                <input type="hidden" class="text input-large" id="student_id" name="student_id" value="{$data.sid}">
                <a href="javascript:void(0);" data-width="large" data-toggle="modal" data-target="#myModal">选择</a>
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">开始上课日期<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" id="start_time" name="start_time" value="{:time_format($data['start_time'],'Y-m-d')}">
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">截止上课日期<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" id="end_time" name="end_time" value="{:time_format($data['end_time'],'Y-m-d')}">
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">费用<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="fee" value="{$data.fee}" onkeyup="clearNoNum(this)">
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">缴费方式<span class="check-tips"></span></label>
            <div class="controls">
                <select name="inputPaymethod" id="inputPaymethod" style="width: 200px;">
                    <volist name="_pay_method" id="paymethod" key="k">
                        <option value="{$k}">{$paymethod}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">备注<span class="check-tips"></span></label>
            <div class="controls">
                <label class="textarea input-large">
                    <textarea name="remark">{$data.remark}</textarea>
                </label>
            </div>
        </div>

        <div class="form-item">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
        <input type="hidden"  name="id" value="{$data.id}" >
        <input type="hidden"  name="grade_id" value="{$Think.get.grade_id}" >
    </form>


    <!-- 学员列表-->
    <div id="myModal" tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×</button>
                    <h4 id="myModalLabel" class="modal-title">学员列表</h4>
                </div>
                <div class="modal-body">
                    <table class="sui-table table-bordered" id="all_student_list">
                        <thead>
                        <tr>
                            <th>学号</th>
                            <th>学生</th>
                            <th>家长</th>
                            <th>电话</th>
                            <th>选择</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                        </tbody>
                    </table>

                </div>
                <div class="modal-footer">
                    <form class="sui-form form-search" style="margin-bottom: -26px; margin-right: 550px;">
                    <div class="input-append">
                        <input type="text" class="span2" id="search_name" placeholder="输入学生名字查询">
                        <button type="button" class="sui-btn" id="search_stu">查 询</button>
                    </div>
                    </form>
                    <button type="button" data-ok="modal" class="sui-btn btn-primary btn-large" id="_xuanze">确 定</button>
                    <button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">取 消</button>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="script">
    <script type="text/javascript">

        $(function(){
            $("#_xuanze").click(function(){
                var data_id = $("input[name='radio']:checked").attr('data_id');
                var data_name = $("input[name='radio']:checked").attr('data_name');
                $("#student_id").val(data_id);
                $("#student_name").html(data_name);
            });
        });

        $('#myModal').on('show', function(e){
            $("#search_stu").click();
        });

        $("#search_stu").click(function(){
            var search_name = $("#search_name").val();
            $.ajax({
                type: 'POST',
                url: "{:U('ajaxGetStudent')}",
                data: "grade_id={$grade_id}&search_name="+search_name,
                success: function (res) {
                    var html = '';
                    for(var i = 0;i < res.length; i++) {
                        html += '<tr>\n' +
                            '<td>'+res[i].noid+'</td>\n' +
                            '<td>'+res[i].name+'</td>\n' +
                            '<td>'+res[i].parent_name+'</td>\n' +
                            '<td>'+res[i].parent_phone+'</td>\n' +
                            '<td><label class="radio-pretty inline">\n' +
                            '    <input type="radio" name="radio" data_id="'+res[i].id+'" data_name="'+res[i].name+'"><span>选择</span>\n' +
                            '  </label></td>\n' +
                            '</tr>';
                    }
                    $("#all_student_list tbody").html(html);
                }
            });
        });

        laydate.render({
            elem: '#start_time'
        });
        laydate.render({
            elem: '#end_time'
        });

        function clearNoNum(obj)
        {
            obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
            obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
            obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
            obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        }
        //导航高亮
        highlight_subnav('{:U('Grade/index')}');
    </script>
</block>
